package net.xdclasss.demo_project.mapper;

import net.xdclasss.demo_project.domain.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserMapper {
    private static Map<String, User> userMap = new HashMap<>();
    static{
        userMap.put("jack",new User(1,"jack","123"));
        userMap.put("tom",new User(2,"tom","456"));
        userMap.put("jerry",new User(3,"jerry","789"));

    }

    /**
     * 登录
     * @param username
     * @param pwd
     * @return
     */
    public User login(String username, String pwd){
        User user = userMap.get(username);
        if (user == null){
            return null;
        }
        if (user.getPwd().equals(pwd)){
            return user;
        }
        return null;
    }

    /**
     * 返回全部用户
     * @return
     */
    public List<User> listUser(){
        List<User> list = new ArrayList<>();
        list.addAll(userMap.values());
        return list;
    }
}
